#!/usr/bin/env python

import pyxmppclient
from pyxmpp.all import Presence,Message
import userman
import logging

def sendMessage(jid, body):
    logging.info(u'sendMessage ' + jid + ' ' + body)
    pyxmppclient.clientInstance.stream.send(
            Message(
                    to_jid = jid,
                    from_jid = None,
                    stanza_type = 'chat',
                    body = body
                )
        )
    logging.info(u'sendMessaged ' + jid + ' ' + body)

def sendInvite(jid):
    pass

def sendMessageToOther(jid, body):
    id = jid.split('/')[0]
    logging.info(u'sendMessageToOther ' + jid)
    us = userman.getUsers(True)
    for u in us:
        if (u.jid != id.lower()):
            sendMessage(u.jid, body)
    logging.info(u'sendMessageToOthered ' + jid)

def sendPresence(body):
    logging.info(u'sendPresence '+ body)
    pyxmppclient.clientInstance.stream.send(
            Presence(status=body)    
        )
    logging.info(u'sendPresenced ' + body)
